class Solution {
public:
    int lengthOfLastWord(string s) {
        int ret = 0;
        int n = s.size();
        int i = n - 1;
        for (; i >= 0; i--)
        {
            if (s[i] != ' ') break;
        }
        for (; i >= 0; i--)
        {
            if (s[i] == ' ') break;
            ret++;
        }
        return ret;
    }
};
class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        if (nums.size() == 0) return { -1, -1 };

        int n = nums.size();
        int left = 0, right = n - 1;
        while (left < right)
        {
            int mid = (right - left) / 2 + left;
            if (nums[mid] < target) left = mid + 1;
            else right = mid;
        }
        if (nums[left] != target) return { -1, -1 };
        int begin = left;
        right = n - 1;
        while (left < right)
        {
            int mid = (right - left + 1) / 2 + left;
            if (nums[mid] <= target) left = mid;
            else right = mid - 1;
        }
        return { begin, right };
    }
};